package com.coda.clouddisk.controller.impl;

import com.coda.clouddisk.annotation.Loggable;
import com.coda.clouddisk.controller.SuperController;
import com.coda.clouddisk.controller.inter.KeSunAttachmentController;
import com.coda.clouddisk.entity.KeSunAttachment;
import com.coda.clouddisk.entity.KesunReturn;
import com.coda.clouddisk.mapper.KeSunAttachmentMapper;
import com.coda.clouddisk.service.impl.KeSunAttachmentServiceImpl;
import com.coda.clouddisk.service.inter.KeSunAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.net.MalformedURLException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;

@RestController
@RequestMapping("/clouddisk/keSunAttachment")
public class KeSunAttachmentControllerImpl extends SuperController implements KeSunAttachmentController {

    @Autowired
    private KeSunAttachmentServiceImpl keSunAttachmentService;

    @Override
    public Map<String, Object> convertData(Map<String, Object> data) {
        setSuperService(keSunAttachmentService);
        return data;
    }
    /**
     * 文件上传
     */
    @Override
    @PostMapping("/upload")
    @Loggable("文件上传")
    public KesunReturn uploadFile(KeSunAttachment keSunAttachment, MultipartFile file) {
        KesunReturn kesunReturn = keSunAttachmentService.uploadFile(keSunAttachment, file);
        return kesunReturn;
    }

    /**
     * 文件下载
     * @return
     */
    @Override
    @GetMapping("/download")
    @Loggable("文件下载")
    public ResponseEntity<Resource> downloadFile(String id) throws MalformedURLException {
        return keSunAttachmentService.downloadFile(id);
    }

    /**
     * 将文件添加进回收站
     */
    @PutMapping("/toRubbish")
    @Loggable("将文件添加进回收站")
    public KesunReturn toRubbish(@RequestBody Map<String,Object> data){
        return keSunAttachmentService.toRubbish(data);
    }

    /**
     * 按时间分类查找文件
     */
    @GetMapping("/getFileByTime")
    @Loggable("按时间分类查找文件")
    public KesunReturn getFileByTime(@RequestParam Map<String,Object> map){
        return keSunAttachmentService.getFile(map);
    }

}
